package com.dxc.intern.controller;


import com.dxc.intern.entity.Page;
import com.dxc.intern.entity.Result;
import com.dxc.intern.entity.Resume;
import com.dxc.intern.service.PrimaryScreeningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 初筛数据表 前端控制器
 * </p>
 *
 * @author zhangchengming
 * @since 2022-02-21
 */
@CrossOrigin
@RestController
@RequestMapping("/primaryScreening")
public class PrimaryScreeningController {



    @Autowired
    private PrimaryScreeningService primaryScreeningService;

    /**
     * 分页查询简历
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping("/page")
    public Result<Page<Resume>> page(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){
        Page<Resume> page =primaryScreeningService.page(pageNo,pageSize);

        return Result.success("简历分页", page);
    }
    /**
     * 分页模糊查询简历
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
    @RequestMapping("/selectLike")
    public Result<Page<Resume>> selectLike(@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                           @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                           @RequestBody Resume resume){
        Page<Resume> page =primaryScreeningService.selectLike(pageNo,pageSize,resume);

        return Result.success("简历模糊查询分页", page);
    }



    /**
     * 删除简历 通过简历id
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public Result<String> delete(@RequestParam(name = "id") Long id){
        boolean b=primaryScreeningService.delete(id);
        return b ? Result.success("删除成功", primaryScreeningService.toString()) :
                Result.error("删除失败", "false");
    }


    /**
     * 更新简历状态
     *
     * @param resume
     * @return
     */
    @PutMapping("/update")
    public Result<String> update(@RequestBody Resume resume){
        boolean b=primaryScreeningService.addRoster(resume);
        boolean c=primaryScreeningService.delete(resume.getId());
        return b ? Result.success("更新成功",resume.toString()) :
                Result.error("更新失败", resume.toString());

    }
}
